<template>
  <div class="search-bar">
    <el-form :inline="true" :model="formItem" class="form-filter" size="mini">
      <el-form-item>
        <el-select v-model="formItem.s_status" clearable placeholder="请选择状态" @change="statusChange">
          <el-option v-for="item in inventoryDutyStatus" :key="item.code" :label="item.text" :value="item.code" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-input v-model="formItem.s_name" clearable placeholder="请输入任务名称..." />
      </el-form-item>
      <el-form-item>
        <el-button plain icon="el-icon-search" @click="search" />
        <!-- <el-button plain icon="el-icon-search" @click="search">查询</el-button>
        <el-button plain icon="el-icon-refresh-left" @click="reset">重置</el-button> -->
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { getInfo } from '@neu/biz-core/api/user'
import { getToken } from '@neu/biz-core/utils/auth'
import { INVENTORY_EXECUTE_STATUS as STATUS } from '@neu/dcam-ui/utils/constants'
// 定义一个查询表单原始项
const formItem = {
  s_name: '',
  s_status: '',
  s_notstatus: '',
  s_userId: ''
}

export default {
  name: 'InventoryExecuteTableFilter',
  props: {
    // 查询按钮会通过属性filter，进行api操作
    filter: {
      required: true,
      type: Function
    },
    notstatus: {
      type: Boolean,
      default: null
    },
    userId: {
      type: Boolean,
      default: null
    }
  },
  data() {
    return {
      formItem: {
        ...formItem
        // s_planId: this.$route.query.planId ? this.$route.query.planId : -1
      },
      /** 计划状态 */
      inventoryDutyStatus: STATUS
    }
  },
  created() {
    // // 获取盘点计划状态
    // status().then(res => {
    //   this.inventoryDutyStatus = res.data
    //   this.inventoryDutyStatus.splice(this.inventoryDutyStatus.findIndex(item => item.code === 'created'), 1)
    // })
  },
  methods: {
    // 查询按钮点击事件处理
    search: function() {
      getInfo(getToken()).then(response => {
        const userData = response.data
        this.formItem.s_userId = userData.userId
        this.formItem.s_notstatus = 'created'
        this.filter(this.formItem)
      })
    },
    // 重置按钮点击事件处理
    reset: function() {
      this.formItem = {
        ...formItem
        // s_planId: this.$route.query.planId ? this.$route.query.planId : -1
      }
      this.search()
    },
    statusChange: function() {
      this.search()
    }
  }
}
</script>
